package com.bluedot.bank.action;

import com.bluedot.bank.dao.user.User;
import com.bluedot.bank.dao.user.UserDao;
import com.bluedot.bank.dao.user.UserDaoImpl;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class LoginAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private User user;
	

	/**
	 * @return the user
	 */
	public User getUser() {
		return user;
	}

	/**
	 * @param user
	 *            the user to set
	 */
	public void setUser(User user) {
		this.user = user;
	}

	@Override
	public String execute() throws Exception {
		UserDao userDao=new UserDaoImpl();
		User u=userDao.findByName(user.getUserName());
		
			

		if(u==null){
			this.addActionError("用户名无效");
				return "input";
		}else{
			if("未激活".equals(u.getStatus())){
				this.addActionError("用户未激活");
				return "input";
			}
			if(!(u.getPassWord().equals(user.getPassWord()))){
				this.addActionError("密码错误");
				return "input";
			}
				
		}
		ActionContext.getContext().getSession().put("user", u);
		return SUCCESS;
	}
}
